package com.ruoyi.sports.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.sports.mapper.MessageMapper;
import com.ruoyi.sports.domain.Message;
import com.ruoyi.sports.service.IMessageService;

/**
 * 留言Service业务层处理
 *
 * @author ZJH
 * @date 2023-03-13
 */
@Service
public class MessageServiceImpl implements IMessageService
{
    @Autowired
    private MessageMapper messageMapper;

    /**
     * 查询留言
     *
     * @param messageId 留言主键
     * @return 留言
     */
    @Override
    public Message selectMessageByMessageId(Long messageId)
    {
        return messageMapper.selectMessageByMessageId(messageId);
    }

    /**
     * 查询留言列表
     *
     * @param message 留言
     * @return 留言
     */
    @Override
    public List<Message> selectMessageList(Message message)
    {
        return messageMapper.selectMessageList(message);
    }

    /**
     * 新增留言
     *
     * @param message 留言
     * @return 结果
     */
    @Override
    public int insertMessage(Message message)
    {
        message.setCreateTime(DateUtils.getNowDate());
        return messageMapper.insertMessage(message);
    }

    /**
     * 修改留言
     *
     * @param message 留言
     * @return 结果
     */
    @Override
    public int updateMessage(Message message)
    {
        message.setUpdateTime(DateUtils.getNowDate());
        return messageMapper.updateMessage(message);
    }

    /**
     * 批量删除留言
     *
     * @param messageIds 需要删除的留言主键
     * @return 结果
     */
    @Override
    public int deleteMessageByMessageIds(Long[] messageIds)
    {
        return messageMapper.deleteMessageByMessageIds(messageIds);
    }

    /**
     * 删除留言信息
     *
     * @param messageId 留言主键
     * @return 结果
     */
    @Override
    public int deleteMessageByMessageId(Long messageId)
    {
        return messageMapper.deleteMessageByMessageId(messageId);
    }

    @Override
    public List<Message> selectMessageAboutMe(Long userId) {
        List<Message> myMessageList= messageMapper.selectMyMessage(userId);
        if (myMessageList.size()!=0){
            for (Message m:myMessageList){
                List<Message> messages= messageMapper.selectReply(m.getMessageId());
                myMessageList.addAll(messages);
            }
        }
        return myMessageList;
    }
}
